package cn.fzkj.gulimall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.fzkj.gulimall.ware.vo.PurchaseDoneVo;
import cn.fzkj.gulimall.ware.vo.PurchaseMergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.fzkj.gulimall.ware.entity.PurchaseEntity;
import cn.fzkj.gulimall.ware.service.PurchaseService;
import cn.fzkj.common.utils.PageUtils;
import cn.fzkj.common.utils.R;



/**
 * 采购信息
 *
 * @author chenxin
 * @email chenxin@gmail.com
 * @date 2022-02-17 22:59:33
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 完成采购
     */
    @RequestMapping(value = "/finish", method = RequestMethod.POST)
    public R purchaseFinish(@RequestBody PurchaseDoneVo vo){
        purchaseService.finishPurchase(vo);
        return R.ok();
    }

    /**
     * 领取采购单
     * @param ids 要领取的采购单id
     */
    @RequestMapping(value = "/receive", method = RequestMethod.POST)
    public R receivePurchases(@RequestBody List<Long> ids){

        purchaseService.receivePurchases(ids);
        return R.ok();
    }

    /**
     * 获取没有被领取的采购单
     */
    @RequestMapping(value = "/unreceive/list", method = RequestMethod.GET)
    public R getUnReceiveList(@RequestParam Map<String, Object> params){

        PageUtils page = purchaseService.getUnReceiveList(params);

        return R.ok().put("page", page);
    }

    /**
     * 合并采购需求
     */
    @RequestMapping(value = "/merge", method = RequestMethod.POST)
    public R mergePurchase(@RequestBody PurchaseMergeVo purchaseMergeVo){

        purchaseService.mergePurchase(purchaseMergeVo);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
